#include "generic_bitwise.h"

#include <QString>

#include "bit_range.h"


namespace BitWin
{


// Internal usage staff anonymous namespace
namespace
{

// GenericBitwise child class encapsulating no data
class EmptyBitwise: public GenericBitwise
{
    EmptyBitwise();
    friend PGenericBitwise GenericBitwise::empty();

public:
    virtual QString bitwise() const;
    virtual QString hex() const;
    virtual QString dec() const;
};


EmptyBitwise::EmptyBitwise()
{}

QString EmptyBitwise::bitwise() const
{
    return QString();
}

QString EmptyBitwise::hex() const
{
    return QString();
}

QString EmptyBitwise::dec() const
{
    return QString();
}


} // Anonymous namespace end


GenericBitwise::GenericBitwise()
{}

GenericBitwise::~GenericBitwise()
{}

QString GenericBitwise::bitwise(const BitRange& range) const
{
    QString b = bitwise();
    QString m = b.mid(range.begin(), range.length());
    
    return QString(b.length(),' ')
        .replace(range.begin(), m.length(), m)
    ;
}

PGenericBitwise GenericBitwise::empty()
{
    return PGenericBitwise(new EmptyBitwise());
}


} // BitWin namespace end
